package jco3.JCoTable;

import com.sap.conn.jco.JCoField;
import com.sap.conn.jco.JCoRecordMetaData;
import com.sap.conn.jco.JCoTable;

public class JCoUtils {
	public static void printJCoTable(JCoTable jcoTbale) {
		// header

        // JCoRecordMeataData is the meta data of either a structure or a table.
        // Each element describes a field of the structure or table. 
		JCoRecordMetaData tableMeta = jcoTbale.getRecordMetaData();
		for(int i=0;i<tableMeta.getFieldCount();i++) {
			System.out.println(String.format("%s\t", tableMeta.getName(i)));
		}
		System.out.println();
		
		for(int i=0;i<jcoTbale.getNumRows();i++) {
			// Sets the row pointer to the specified position(beginning from zero)
			jcoTbale.setRow(i);
			
			// Each line is of type JCoStructure
			for(JCoField fld:jcoTbale) {
				System.out.println(String.format("%s\t", fld.getValue()));
			}
			System.out.println();
		}
	}
}
